home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / gfx / misc / pchglib12.lha / ParsePCHG.c < prev    next >
C/C++ Source or Header  |  1992-11-15  |  3KB  |  76 lines

  1. #include <proto/intuition.h>
  2. #include <proto/exec.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <iff/pchg.h>
  6. #include <clib/pchglib_protos.h>
  7.  
  8. #if INCLUDE_VERSION<36
  9. FAILURE!! Amiga includes version<36
  10. #endif
  11.  
  12.  
  13. /****** pchg.lib/PCHG_ParsePCHG ******************************************
  14.  
  15.    NAME
  16.        PCHG_ParsePCHG -- Parse a PCHG chunk and build Copperlist.
  17.  
  18.    SYNOPSIS
  19.        Error = PCHG_ParsePCHG(PCHG, ViewPort);
  20.  
  21.        LONG PCHG_ParsePCHG(struct PCHGHeader *, struct ViewPort *);
  22.  
  23.    FUNCTION
  24.        I-do-all-for-you function. PCHG_ParsePCHG() frees you from
  25.        every hassle. You simply pass it the content of the PCHG
  26.        chunk (i.e., what follows the IFF chunk size) and a pointer
  27.        to your ViewPort. The Copperlist will be built and stuffed in.
  28.  
  29.    INPUTS
  30.        PCHG          - A pointer to the contents of the PCHG chunk.
  31.        ViewPort      - A pointer to the ViewPort that will receive the
  32.                        Copperlist described in the PCHG chunk.
  33.  
  34.    RESULT
  35.        Error will be set to 0 if everything OK. Otherwise you can
  36.        the error listed in iff/pchg.h (PCHGERR_NOMEM, etc.).
  37.  
  38.    EXAMPLE
  39.  
  40.    NOTES
  41.        The Copperlist created by this function will be
  42.        automatically deallocated when you call CloseScreen() if
  43.        you're using the ViewPort of an Intuition Screen.
  44.        This function parses the chunk and then calls
  45.        PCHG_SetUserCopList(); thus, it needs grahics.library.
  46.        After calling it, you will probably need a RethingDisplay()
  47.        if you're using an Intuition Screen, or the suitable graphics
  48.        calls (MrgCop() etc.) if you're directly handling the
  49.        ViewPort.
  50.  
  51.    BUGS
  52.  
  53.    SEE ALSO
  54.        PCHG_SetUserCopList(), iff/pchg.h
  55.  
  56. *****************************************************************************/
  57.  
  58. LONG PCHG_ParsePCHG(struct PCHGHeader *PCHG, struct ViewPort *ViewPort) {
  59.  
  60.     void *PCHGDecomp = NULL;
  61.     struct PCHGCompHeader *pch;
  62.  
  63.     if (PCHG->Compression == PCHG_COMP_HUFFMANN) {
  64.         pch = (void *)&PCHG[1];
  65.         if (PCHGDecomp = AllocMem(pch->OriginalDataSize, MEMF_PUBLIC | MEMF_CLEAR))
  66.             PCHG_FastDecomp((char *)&pch[1]+pch->CompInfoSize, PCHGDecomp, (WORD *)((char *)&pch[1]+pch->CompInfoSize-2), pch->OriginalDataSize);
  67.         else return(PCHGERR_NOMEM);
  68.         PCHG_SetUserCopList(0, 0, ViewPort, PCHG, PCHGDecomp, (ULONG *)PCHGDecomp+(PCHG->LineCount+31)/32);
  69.     }
  70.     else if (PCHG->Compression != PCHG_COMP_NONE) return(PCHGERR_UNKNOWNCOMP);
  71.     else PCHG_SetUserCopList(0, 0, ViewPort, PCHG, (void *)&PCHG[1], (ULONG *)&PCHG[1]+(PCHG->LineCount+31)/32);
  72.  
  73.     if (PCHGDecomp) FreeMem(PCHGDecomp, pch->OriginalDataSize);
  74.     return(0);
  75. }
  76.